const fs = require('fs');
const https = require('https');
const path = require('path');

const fontUrl = 'https://fonts.gstatic.com/s/pressstart2p/v15/e3t4euO8T-267oIAQAu6jDQyK3nVivM.ttf';
const fontPath = path.join(__dirname, 'assets', 'fonts', 'pixel_font.ttf');

if (!fs.existsSync(path.dirname(fontPath))) {
    fs.mkdirSync(path.dirname(fontPath), { recursive: true });
}

const file = fs.createWriteStream(fontPath);
https.get(fontUrl, (response) => {
    response.pipe(file);
    file.on('finish', () => {
        file.close();
        console.log('字体下载完成');
    });
}).on('error', (err) => {
    fs.unlinkSync(fontPath);
    console.error('下载失败:', err.message);
});